package org.glut.wechat.videochat.config;

import org.glut.wechat.videochat.handler.SignalingHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.*;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SignalingHandler signalingHandler; // 注入自定义处理器

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(signalingHandler, "/signaling")  // 绑定到/signaling端点
                .setAllowedOrigins("*")  // 允许跨域
                .addInterceptors(new HttpSessionHandshakeInterceptor());  // 添加握手拦截器
    }
}
